<?php
require_once ("src/db/connectdatabase.php");

function getBankLoan($idloan, $bankid) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id', 'dac_tinh_loan', 'object_dk_loan', 'thu_tuc_loan', 'bankid', 'bankname', 'banklogo');
	$fcon = array('loan_id' => $idloan, 'isavalible' => true);
	$flike = array('bankid' => $bankid);
	return $con -> getvalueall($tbl,$fn,$fcon,$flike,'datecreate');
}

function getIntroLoan($idloan) {
	$con = new ConnectDB();
	$tbl = "loans";
	$fn = array('intro_bank_loan_header');
	$condetion = array('loan_id' => $idloan);
	return $con -> getvalue($tbl, $fn, $condetion);
}

$bankid = "";
if(isset($_GET['bank'])) {
	$bankid = $_GET['bank'];
}

$idloan = "vay_the_chap";
$arrbankloan = getBankLoan($idloan, $bankid);
$arrintrobasic = getIntroLoan($idloan);
?>
<script type="text/javascript">
    document.title = "Vay thế chấp - Tổng hợp các chương trình vay thế chấp tài sản";
</script>
<link rel="stylesheet" type="text/css" href="<?php echo($host) ?>css/layout.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo($host) ?>css/template.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo($host) ?>css/style.css"/>

<script type="text/javascript" src="<?php echo($host) ?>js/jquery.js"></script>

<script type="text/javascript">
	$(document).ready(function(){
		$(".tabsms_container").each(function(){                    
			var parent = $(this).parent().attr("id");
			$(this).hide();                    
			$("#"+parent+" .tabsms_container:first").show();
			var parent_parent = $("#"+parent).parent().attr("id");
			$("#"+parent_parent+" ul.consultant_tab_header li:first").addClass("active");
			$("#"+parent_parent+" ul.consultant_tab_header li").click(function(){
				$("#"+parent_parent+" ul.consultant_tab_header li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$("#"+parent+" .tabsms_container").hide(); //Hide all tab content            
				var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
				$("#"+parent+" .tabsms_container"+activeTab).show(); //Fade in the active ID content
				return false;
			})
		});
	});
</script>
<div class="content">
<!-- Left content -->
	<div class="wrapper_left">
		<div>
		<?php 
            if(count($arrintrobasic) == 1) {
            ?>
            <div class="text11" style="color: #4c4c4c; width: 950px; margin-left: 8px;"><?php echo($arrintrobasic[0][0]) ?></div>
            <?php
            }
            ?>
        </div>
        <div style="clear:both;"></div>
        
		<div class="sh_box prl_showlist">
			<div class="sh_title faq_infos_title">Vay Thế Chấp</div>
			<div><select name="selectbank" class="bankloadselect" id="selectbank" style="width: 185px; height: 26px;" onchange="submit_search_bankloan()"><option value="">--Tất Cả--</option></select></div>
			<div class="clear" style="margin-top: 10px;"><span></span></div>
        <?php
		for ($i = 0; $i < count($arrbankloan); $i++) {
		?>
        	<div id="parent<?php echo($i) ?>" class="product_item_content product_loan_item">
        		<div class="product_item_name">
					<div class="product_item_bankname">
						<a class="product_bank_img" title="<?php echo($arrbankloan[$i][5]) ?>" rel="nofollow">
							<img src="<?php echo($host) ?><?php echo($arrbankloan[$i][6]) ?>" class="product_bank_img" align="<?php echo($arrbankloan[$i][5]) ?>">
						</a>
						<!--<a class="product_bank_name" title=""></a>-->
                        <div><span style="margin-left: 4px; text-align:center;"><a href="<?php echo($host) ?>vay-the-chap/ap-dung-cho-vay-the-chap/bank/<?php echo($arrbankloan[$i][4]) ?>.html"><img src="<?php echo($host) ?>images/dangky.png" /></a></span></div>
					</div>
				</div> 
				<div class="product_loan_tab"> 
					<span class="product_tab_title"><a href="#">Cho vay thế chấp</a></span>  
						<ul class="consultant_tab_header" id="cardinfo<?php echo($i) ?>">                 
							<li class="product_tab product_loan_t1 active"><a class="product_tab" href="#functions">Đặc tính</a></li>                
							<li class="product_tab product_loan_t2"><a class="product_tab" href="#condition">Đối tượng - điều kiện vay</a></li> 
							<li class="product_tab product_loan_t3"><a class="product_tab" href="#procedure">Thủ tục vay vốn</a></li> 
						</ul>    	
					</div>
					<div class="clear"></div>            	
					<div class="product_loan_tab_content" id="tabs<?php echo($i) ?>">
						<div style="display: block;" id="functions" class="tabsms_container"><?php echo($arrbankloan[$i][1]) ?></div>
                		<div style="display: none;" id="condition" class="tabsms_container"><?php echo($arrbankloan[$i][2]) ?></div>
						<div style="display: none;" id="procedure" class="tabsms_container"><?php echo($arrbankloan[$i][3]) ?></div>
					</div>
				<div class="product_content_link">
					<a class="product_bank_name" style="float:left" title="<?php echo($arrbankloan[$i][5]) ?>"><?php echo($arrbankloan[$i][5]) ?></a>
                    <?php 
					$strbanknameurl = $arrbankloan[$i][5];
					$strbanknameurl = rewriteTextUrl(stripUnicode($strbanknameurl));
					?>
					<a href="<?php echo($host) ?>chi-tiet-ngan-hang-cho-vay/<?php echo($arrbankloan[$i][0]) ?>/<?php echo ($strbanknameurl); ?>.html" class="product_content_relate_consultant" rel="nofollow">Xem chi tiết</a>
					<div class="clear"></div>
				</div>
			</div>
			<div class="clear"></div>
         <?php
		}
		 ?>
		</div>
		<div class="clear"></div>
	</div>
    <!-- Right content -->
    <div style="float: right; clear: right; background-image: url(<?php echo($host) ?>images/gray_bg.gif); width: 275px; height: auto; margin-top: 10px;">
        <?php include("formsendapplyloan.php"); ?>
    </div>
    <div class="clear"></div>

</div>
<script>
loadbank();
function loadbank() {
	$.ajax({
		url: "<?php echo($host) ?>src/ajax/ajaxbank.php",
		type: "post",
		data: {act:'getbanks'},
		dataType:"json",
		success: function(response) {
			html = '';
			$.each(response, function(entryIndex, entry){
				html += '<option value="' + entry[0] + '">' + entry[1] + ' (' + entry[0] + ')</option>';
			});
			$('.bankloadselect').append(html);
			$('.bankloadselect').val('<?php echo($bankid) ?>');
		}
	});
}

function submit_search_bankloan() {
	window.location = "<?php echo($host) ?>vay-the-chap/ngan-hang-cho-vay-the-chap/bank/" + $('.bankloadselect').val() + ".html";
}
</script>